package com.linxz.video.adapter;

import android.annotation.SuppressLint;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.linxz.ui.GuiHelper;
import com.linxz.ui.widgets.CircleImageView;
import com.linxz.video.R;
import com.linxz.video.pojo.LiveBroadCastWrapBean;

import java.util.List;

/**
 * @author Linxz
 * 创建日期：2020年06月29日 10:15
 * version：v4.5.4
 * 描述：
 */
public class LiveBroadCastAdapter extends BaseQuickAdapter<LiveBroadCastWrapBean, BaseViewHolder> {

    private OnLiveBroadCastItemClickListener mOnLiveBroadCastItemClickListener;

    public void setOnLiveBroadCastItemClickListener(OnLiveBroadCastItemClickListener onLiveBroadCastItemClickListener){
        this.mOnLiveBroadCastItemClickListener=onLiveBroadCastItemClickListener;
    }

    public LiveBroadCastAdapter(@Nullable List<LiveBroadCastWrapBean> data) {
        super(R.layout.videos_item_livebroadcast, data);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(BaseViewHolder helper, LiveBroadCastWrapBean item) {
        LinearLayout layoutMain=helper.getView(R.id.layoutMain);
        CircleImageView ivAvatar=helper.getView(R.id.ivAvatar);
        TextView tvName=helper.getView(R.id.tvName);
        TextView tvFans=helper.getView(R.id.tvFans);
        TextView tvDesc=helper.getView(R.id.tvDesc);
        ImageView ivConvert=helper.getView(R.id.ivConvert);
        TextView tvAudience=helper.getView(R.id.tvAudience);

        GuiHelper.loadImage(mContext,item.getUser().getHeadimg(),ivAvatar);
        tvName.setText(item.getUser().getName());
        tvFans.setText(item.getUser().getFans()+"粉丝");
        tvDesc.setText(item.getLiveBroadcast().getLbDesc());
        GuiHelper.loadImageWithCorner(mContext,item.getLiveBroadcast().getConvertUtl(),ivConvert,
                5F,
                true,
                true,
                true,
                true);
        tvAudience.setText(item.getLiveBroadcast().getAudience()+"人");
        layoutMain.setOnClickListener(v -> {
            if (mOnLiveBroadCastItemClickListener!=null){
                mOnLiveBroadCastItemClickListener.onClick(item);
            }
        });


    }


    public interface OnLiveBroadCastItemClickListener{
        void onClick(LiveBroadCastWrapBean item);
    }
}
